import com.zhao.dao.UserDao;
import com.zhao.pojo.Cat;
import com.zhao.pojo.Hello;
import com.zhao.pojo.People;
import com.zhao.pojo.Student;
import com.zhao.service.UserService;
import com.zhao.service.UserServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.lang.reflect.Proxy;

public class Mytest {
    public static void main(String[] args) {
        //获取spring的上下文对象
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
        ApplicationContext autoContext = new ClassPathXmlApplicationContext("beans-autowired.xml");

        //测试factory-method
//        UserDao userDao= (UserDao) context.getBean("userDao1");
//        System.out.println(userDao);

//        UserDao userDao2= (UserDao) context.getBean("userDao2");
//        System.out.println(userDao2);

        //我们的对象现在都是在spring中管理了，我们要使用，直接去里面取出来就可以
//        Hello hello = (Hello) context.getBean("hello");
//        System.out.println(hello);
//
//        UserService userService = (UserService) context.getBean("userService");
//        userService.add();

//
//        Student student = context.getBean(Student.class);
//        System.out.println(student);

        //自动装配bean文件
//        People people=autoContext.getBean(People.class);
//        people.getCat().shout();


        //注解装配
//        Cat cat=applicationContext.getBean(Cat.class);
//        System.out.println("注解装配："+cat.name);

        // 通过名称获取bean更可靠
        UserService userService = (UserService) applicationContext.getBean("userService");
//        System.out.println("Actual class: " + userService.getClass().getName());
//        System.out.println("Is proxy? " + Proxy.isProxyClass(userService.getClass()));
        userService.getUserDao();


    }
}
